package com.ruoyi.web.controller.mate;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.MatePurRequisition;
import com.ruoyi.service.IMatePurRequisitionService;
import com.ruoyi.service.IThisStockService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用料采购申请Controller
 *
 * @author ruoyi
 * @date 2020-07-06
 */
@Controller
@RequestMapping("/ruoyi/requisitions")
public class MateMoneyController extends BaseController {
    private String prefix = "ruoyi/requisition";

    @Autowired
    private IMatePurRequisitionService matePurRequisitionService;
    @Resource
    private IThisStockService thisStockService;

    @RequiresPermissions("ruoyi:requisitions:view")
    @GetMapping("/show/{pId}")
    public String requisition(@PathVariable("pId") Long pId,ModelMap map) {

        map.put("pId",pId);
        return prefix + "/requisitionmoney";
    }

    /**
     * 查询用料采购申请列表
     */
    @RequiresPermissions("ruoyi:requisitions:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Long mId) {
        startPage();
        List<MatePurRequisition> list = matePurRequisitionService.selectMatePurRequisitionLists(mId);
        return getDataTable(list);
    }
    /**
     * 查询用料采购申请列表
     */
    @RequiresPermissions("ruoyi:requisitions:list")
    @PostMapping("/lists")
    @ResponseBody
    public TableDataInfo lists(MatePurRequisition matePurRequisition) {
        startPage();
        List<MatePurRequisition> list = matePurRequisitionService.selectMatePurRequisitionList(matePurRequisition);
        return getDataTable(list);
    }

    /**
     * 导出用料采购申请列表
     */
    @RequiresPermissions("ruoyi:requisitions:export")
    @Log(title = "用料采购申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MatePurRequisition matePurRequisition) {
        List<MatePurRequisition> list = matePurRequisitionService.selectMatePurRequisitionList(matePurRequisition);
        ExcelUtil<MatePurRequisition> util = new ExcelUtil<MatePurRequisition>(MatePurRequisition.class);
        return util.exportExcel(list, "requisition");
    }





}
